package net.sansi.v3correctserver.entity;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Objects;

/**
 * Created by Fang
 * create time : 2024/11/4
 * IDE : IntelliJ IDEA
 */

@Api("坐标点")
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class IntPoint extends HashEquals {

    @ApiModelProperty("x坐标")
    private Integer x;

    @ApiModelProperty("y坐标")
    private Integer y;

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int[] toArray() {
        return new int[]{x, y};
    }

    @Override
    public int hashCode() {
        return Objects.hash(getX(), getY());
    }

    public String toString() {
        return StrUtil.format("{x:{},y:{}}", x, y);
    }

    /**
     * 是否相等
     * 1. 判断类型是否相等
     * 2. 判断 x, y 是否相等
     *
     * @param obj 另一个对象
     * @return 是否相等
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null || obj.getClass() != this.getClass()) return false;
        IntPoint t = (IntPoint) obj;
        return t.getX() == this.getX() && t.getY() == this.getY();
    }
}
